import classNames from 'classnames'
import './index.scss'
import { billTypeToName } from '@/constants'
import { useState } from 'react'
import Icon from '@/components/Icon'

const DailyBill = ({ overview }) => {

  const [visible, setVisible] = useState(false)

  return (
    <div className={classNames('dailyBill')} onClick={() => setVisible(!visible)}>
      <div className="header" >
        <div className="dateIcon">
          <span className="date">{overview.date}</span>
          <span
            className={classNames('arrow', visible && 'expand')}
          ></span>
        </div>
        <div className="oneLineOverview">
          <div className="pay">
            <span className="type">支出</span>
            <span className="money">{overview.pay}</span>
          </div>
          <div className="income">
            <span className="type">收入</span>
            <span className="money">{overview.income}</span>
          </div>
          <div className="balance">
            <span className="money">{overview.total}</span>
            <span className="type">结余</span>
          </div>
        </div>
      </div>
      {/* 单日列表 */}
      <div className="billList" style={{ display: !visible && 'none' }}>
        {overview.list.map(item => {
          return (
            <div className="bill" key={item.id}>
              <Icon type={item.useFor} />
              <div className="detail">
                <div className="billType">{billTypeToName[item.useFor]}</div>
              </div>
              <div className={classNames('money', item.type)}>
                {item.money.toFixed(2)}
              </div>
            </div>
          )
        })}
      </div>
    </div>
  )
}

export default DailyBill